package com.dhl.iterator.college;

import com.dhl.iterator.Department;
import com.dhl.iterator.Iterator;

import java.util.List;

/**
 * @title: InfoCollegeIterator
 * @Author danghailiang
 * @Date: 2022/8/20 16:46
 * @Version 1.0
 */
// 迭代器实现
public class InfoCollegeIterator implements Iterator {

    private List<Department> departments;
    // 指针
    private Integer positior = -1;

    public InfoCollegeIterator(List<Department> departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        if (positior >= departments.size() - 1) {
            return false;
        }
        positior += 1;
        return true;
    }

    @Override
    public Object next() {
        return this.departments.get(positior);
    }

    @Override
    public void remove(Object target) {
        departments.remove(target);
    }
}
